import { getBaiduList } from "./baidu.js";
import { getJueJinList } from "./juejin.js";
import { getZhiHuList } from "./zhihu.js";
import { getWeiBoList } from "./weibo.js";
import { getDouyinList } from "./douyin.js";
import { getShaoshupaiList } from "./shaoshupai.js";
import { getBilibiliList } from './bilibili.js'
import {
  getJuejinListApi,
  getShaoshuListApi,
  getTiebaListApi,
  getZhihuListApi,
  getJinritoutiaoListApi,
  getBilibiliListApi
} from "./api.js";

const data = {
  baidu: {
    api: "",
    browser: getBaiduList,
  },
  juejin: {
    api: getJuejinListApi,
    browser: getJueJinList,
  },
  zhihu: {
    api: getZhihuListApi,
    browser: getZhiHuList,
  },
  weibo: {
    api: "",
    browser: getWeiBoList,
  },
  douyin: {
    api: "",
    browser: getDouyinList,
  },
  shaoshupai: {
    api: getShaoshuListApi,
    browser: getShaoshupaiList,
  },
  tieba: {
    api: getTiebaListApi,
    browser: "",
  },
  jinritoutiao: {
    api: getJinritoutiaoListApi,
    browser: "",
  },
  bilibili: {
    api: getBilibiliListApi,
    browser: getBilibiliList,
  },
};

const getList = async (id) => {
  if (data[id].api) {
    let res = await data[id].api(id);
    return res;
  }
  let list = await data[id].browser(id);
  return list;
};


const getListApi = async (a) => {
  let arr = a.map((item)=>{
    if(data[item.id].api){
      return data[item.id].api(item.id);
    }else{
      return data[item.id].browser(item.id);
    }
  });
  let res = await Promise.all(arr)
  return res
};

export { getList,getListApi };
